var gl_vue_vm_list_asset_html = $('#vue_vm_list_asset').html();
var roomAssetDamagedArray = [];

$(function() {
	$('#vue_vm_list_asset').hide();
	$('#vue_vm_list_asset_forDamage').hide();
	$('#vue_vm_list_asset_compensate').hide();
});

load_roomAsset_by_roomId = function(roomId) {
	$('#vue_vm_list_asset').hide();
	$('#vue_vm_list_asset_forDamage').hide();
	$('#vue_vm_list_asset_compensate').hide();
	
	$('#roomNumber').text('');
	$('#roomType').text('');
	
	if(!roomId || roomId=='') {return;}

	find_basic_by_json(path+'/roomAsset/findByRoomId', {roomId: roomId}, function(response) {
		$('#vue_vm_list_asset').html(gl_vue_vm_list_asset_html);
		
		roomAssetDamagedArray = response.data;
		
		if($('#vue_vm_list_asset').length > 0) {
			new Vue({
				el: '#vue_vm_list_asset',
				data: {
					todos: response.data
				}
			});
		}
		
		if($('#vue_vm_list_asset_forDamage').length > 0) {
			new Vue({
				el: '#vue_vm_list_asset_forDamage',
				data: {
					todos: roomAssetDamagedArray
				},
				methods: {
					roomAssetDamaged_save:function(todo) {
						todo.damagedQuantity = parseInt($('#'+todo.assetId+'_damagedQuantity').val());
						todo.damagedCause = $('#'+todo.assetId+'_damagedCause').val();
						todo.handleStatus = 0;
						
						save_basic(path+'/roomAssetDamaged/save', {roomAssetDamaged:todo}, function() {
							alert('报损成功');
						});
					}
				}
			});
		}
		
		if($('#vue_vm_list_asset_compensate').length > 0) {
			new Vue({
				el: '#vue_vm_list_asset_compensate',
				data: {
					todos: roomAssetDamagedArray
				},
				methods: {
					roomAssetCompensate_save:function(todo) {
						todo.subjectRoomId = getLoginedUser()? getLoginedUser().subjectRoomId: '';
						todo.subjectRoomName = getLoginedUser()? getLoginedUser().subjectRoomName: '';
						todo.createId = getLoginedUser()? getLoginedUser().staffId: '';
						todo.updateId = getLoginedUser()? getLoginedUser().staffId: '';
						todo.beHospitalId = pageParam.beHospitalId;
						todo.elderId = pageParam.elderId;
						todo.compQuantity = parseInt(todo.compQuantity);
						todo.price = todo.assetForm.price;
						todo.compMoney = (todo.price*todo.compQuantity).toFixed(2);
						todo.compStatus = 0;
						
						if(isEmpty(todo.compQuantity)) {
							alert('请输入赔偿件数，且赔偿件数不能为0');
							return;
						}
						
						if(todo.compQuantity > todo.quantity) {
							alert('赔偿件数不能大于资产件数');
							return;
						}
						
						save_basic(path+'/roomAssetComp/save', {roomAssetComp:todo}, function() {
							$('#' + todo.assetId + '_row').remove();
							alert(todo.assetName+' 赔偿保存成功');
						});
					}
				}
			});
		}
		
		$('#vue_vm_list_asset').show();
		$('#vue_vm_list_asset_forDamage').show();
		$('#vue_vm_list_asset_compensate').show();
		if(selectedRoom) {
			$('#roomNumber').text(selectedRoom.roomNumber);
			$('#roomType').text(selectedRoom.roomType);
		}
	});
}